package com.liunian.algorithmstudy.stackandqueue;

import java.util.Stack;

class MyQueue {

    private static Stack<Integer> stackIn;
    private static Stack<Integer> stackOut;

    public MyQueue() {
        stackIn = new Stack<>();
        stackOut = new Stack<>();
    }
    
    public void push(int x) {
        stackIn.push(x);
        if (stackOut.isEmpty()) {
            while (!stackIn.isEmpty()) {
                stackOut.push(stackIn.pop());
            }
        }
    }
    
    public int pop() {
        if (!stackOut.isEmpty()){
            return stackOut.pop();
        }
        while (!stackIn.isEmpty()) {
            stackOut.push(stackIn.pop());
        }
        return stackOut.pop();
    }
    
    public int peek() {
        if (this.empty()) {
            return 0;
        }
        int res = pop();
        stackOut.push(res);
        return res;
    }
    
    public boolean empty() {
        if (stackOut.isEmpty() && stackIn.isEmpty()) {
            return true;
        }
        return false;
    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.peek();
 * boolean param_4 = obj.empty();
 */